//
//  CLOrderDetailViewController.swift
//  CLEasyBBQ
//
//  Created by simon zhao on 2017/4/5.
//  Copyright © 2017年 simon zhao. All rights reserved.
//

import UIKit

class CLOrderDetailViewController: CLBaseNavViewController,UITableViewDelegate,UITableViewDataSource{
    
    let reuStr = "DetailCell"

    override func viewDidLoad() {
        super.viewDidLoad()
        
//        self.navigationController = CLNavigationController.init(titleName: "订单详情", leftimageName: "itemBack", rightImageName: "Order_tel")
        
//        
//        if let nav = self.navigationController as? CLNavigationController {
//    nav.setNaviStyle(titleName: "订单详情", leftimageName: "itemBack", rightImageName: "Order_tel");
//            
////            self.navigationController.setNaviStyle(titleName: "订单详情", leftimageName: "itemBack", rightImageName: "Order_tel")
//        print(type(of:self.navigationController!))
//
//        }
        
    

        
//        self.navigationItem.title = "订单详情"
//        self.navigationController?.navigationBar.barTintColor = UIColor.rgbColorFromHex(rgb: 0x00bbd4)
//
//        let btn = UIButton.init(type: .custom)
//        btn.frame = CGRect(x:15,y:5,width:22,height:22)
//        btn.setBackgroundImage(UIImage.init(named: "itemBack"), for: .normal)
//        btn.addTarget(self, action: #selector(backToOrder), for: .touchUpInside)
//        self.navigationItem.leftBarButtonItem = UIBarButtonItem.init(customView: btn)
//        
//        
//        let rightBtn = UIButton.init(type: .custom)
//        rightBtn.frame = CGRect(x:0,y:0,width:22,height:22)
//        rightBtn.setBackgroundImage(UIImage.init(named: "Order_tel"), for: .normal)
//        rightBtn.addTarget(self, action: #selector(callPhone), for: .touchUpInside)
//        self.navigationItem.rightBarButtonItem = UIBarButtonItem.init(customView: rightBtn)
        
        
        // Do any additional setup after loading the view.
        let titleView = self.loadTitleView()
        self.view.bringSubview(toFront: titleView)
        self.view.addSubview(titleView)
        let detailTableview = UITableView.init(frame: CGRect(x:0,y:titleView.frame.maxY ,width:self.view.frame.width,height:self.view.frame.height - titleView.frame.size.height))
        detailTableview.delegate = self
        detailTableview.dataSource = self
        detailTableview.register(CLorderDetailTableViewCell.self, forCellReuseIdentifier: reuStr)
        self.view.addSubview(detailTableview)
        


    }
    
    func callPhone()  {
        
        
    }
    
    
    func loadTitleView() -> UIView{
    
        let labelWidth = self.view.frame.width/5.0
        let labelHeight = 45.0
        let nameArr = ["序号","菜名","数量","单价","小计"]
        
       let titleView = UIView.init(frame: CGRect(x:0,y:64,width:self.view.frame.width,height:45))
       titleView.backgroundColor = UIColor.white
        
        for count in 0...4 {
            
            let label = UILabel.init(frame: CGRect(x:CGFloat(count)*labelWidth,y:CGFloat(0),width:labelWidth,height:CGFloat(labelHeight)))
            label.text = nameArr[count]
            label.textColor = UIColor.darkGray
            label.textAlignment = NSTextAlignment.center
            titleView.addSubview(label)
        }
        let lineView = UIView.init(frame: CGRect(x:CGFloat(0),y:CGFloat(labelHeight-1),width:self.view.frame.width,height:1))
        lineView.backgroundColor = UIColor.lightGray
        titleView.addSubview(lineView)
        
        return titleView
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}

extension CLOrderDetailViewController {
    
    @objc(numberOfSectionsInTableView:) func numberOfSections(in tableView: UITableView) -> Int {
        
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return 10
    }
    
    @objc(tableView:cellForRowAtIndexPath:) func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell : CLorderDetailTableViewCell = tableView.dequeueReusableCell(withIdentifier: reuStr) as! CLorderDetailTableViewCell
        
        cell.seqLabel.text = String(indexPath.row)
        cell.nameLabel.text = "黄瓜"
        cell.numberLabel.text = "1"
        cell.priceLabel.text = "2.0元"
        cell.totalLabel.text = "2.0元"
    
        return cell
    }
}
